<!DOCTYPE html>

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="wt.lifecycle.LifeCycleTemplate"%>
<%@page import="wt.lifecycle.LifeCycleHelper"%>
<%@page import="java.util.Vector"%>
<%@page import="wt.lifecycle.PhaseTemplate"%>
<%@page import="shmged.com.shlcm.utils.CmCreateUtil"%>
<%@page import="wt.fc.ReferenceFactory"%><html>
<head>
	<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="java.util.Calendar"%>
    <%@page import="wt.httpgw.URLFactory"%>
	<title>费用报销列表</title>
</head>
<%
	String baseUrl = new URLFactory().getBaseHREF();
	Calendar cal = Calendar.getInstance(); 
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
	String cdate = sdf.format(cal.getTime()); 
	LifeCycleTemplate lct=LifeCycleHelper.service.getLifeCycleTemplate("报销单生命周期");
	Vector phaseVector=LifeCycleHelper.service.getPhaseTemplates(lct);
	String[] types=CmCreateUtil.getReimbursementType();
%>
<body>
	<center>
	<div style="margin:10px 0;"></div>
	<div class="easyui-layout" style="width:700px;height:500px;">
		<div class="easyui-panel" data-options="split:true" style="height:50px;" align="right">
		<div style="margin:10px 0;"></div>
		    <a href="javascript:void(0)" class="easyui-linkbutton" id="btn_CreateRB" onclick="browseCreateProjectReimbursement()">创建项目报销</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" id="btn_CreateRB" onclick="browseCreateCommonReimbursement()">创建公共报销</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" id="btn_DeleteRB" onclick="javaScript:deleteSelections('#rbTable','费用报销')">删除报销单</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" id="btn_UpdateRB" onclick="editReimbursement()">修改报销单</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" id="btn_ExportRB" onclick="javaScript:downloadFiles('#rbTable')">导出EXECL</a>
		</div>
		<div style="margin:10px 0;"></div>
		<div class="easyui-panel" title="报销单查询" data-options="split:true,collapsible:true" style="height:125px;" align="center">
			<table>
			<tr>
				<td align="right">单据号:</td><td><input type="text" id="rbNumber" name="rbNumber"></input></td>
				<td align="right">报销金额:</td><td align="left"><input type="text" id="beginMoney" name="beginMoney" size="15">-<input type="text" id="endMoney" name="endMoney" size="15"></input></td>
			</tr>
			<tr>
				<td align="right">单据状态:</td><td align="left"><select id="rbState" name="rbState">
				<option value="">全部</option>
				<%
				for (int j=0; j<phaseVector.size(); j++) {
					PhaseTemplate phase=(PhaseTemplate)phaseVector.get(j);
					%>
						<option value="<%=phase.getPhaseState() %>"><%=phase.getName() %></option>
					<% 
				} %>
				</select></td>
				<td>报销日期:</td><td><input class="easyui-datebox" id="rbBeginTime"  name="rbBeginTime" data-options="formatter:myformatter,parser:myparser"></input>-<input id="rbEndTime" name="rbEndTime" class="easyui-datebox" data-options="formatter:myformatter,parser:myparser"></input></td>
			</tr>
			<tr>
				<td>单据类型:</td><td align="left"><select id="rbType" name="rbType">
				<option value="">全部</option>
				<% for(int i=0;i<types.length;i++){
					%>
					<option value="<%=types[i] %>"><%=types[i] %></option>
					<% 
				} %>
				</select></td>
				<td colspan="2"><a href="javascript:void(0)" class="easyui-linkbutton" id="btn_SearchRB" onclick="searchRBTable()">查询</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" id="btn_SearchRB" onclick="initDocTable('all')">查询全部</a>
				</td>
			</tr>
			</table>
		
		</div>
		<div style="margin:10px 0;"></div>
		<table id="rbTable" class="easyui-datagrid" title="报销单" style="height:280px" data-options="rownumbers:true,singleSelect:false">
			
		</table>
	</div>
	</center>
	<script type="text/javascript">
		initDocTable("mm");
		function initDocTable(stat){
			
			var url='<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/jspGetReimbursementList.jsp';
			  $('#rbTable').datagrid({   
			      url:url,
			      queryParams:{stat:stat},
			      nowrap:false,
			      loadMsg:'正在加载数据，请稍等。。。',
				  fitColumns: true,
			      columns:[[   
					  {field:'id',title:'id',width:100,checkbox:true},  
					  {field:'name',title:'单据号',width:60,
						  //添加超级链 
		                     formatter:function(value,rowData,rowIndex){
		                    		 return "<a href='javaScript:void(0)' onclick=\"javaScript:showReimbursement('"+rowData.id+"')\">"+rowData.name+"</a>";  
				          }}, 
			          {field:'ProjectNo',title:'项目编号',width:40}, 
			          {field:'ProjectName',title:'项目名称',width:60},
			          {field:'state',title:'单据状态',width:40},
			          {field:'Sum',title:'报销金额',width:40},
			          {field:'PayMethod',title:'付款方式',width:40},
			          {field:'RefeBursementType',title:'单据类型',width:40},
			          {field:'Time',title:'报销日期',width:60}
			      ]] 
			    }); 
		}
		
		function initRBTable(date)
		{
			alert(date);
		}

		function searchRBTable()
		{
			var rbNumber=$("#rbNumber").val();
			var beginMoney=$("#beginMoney").val();
			var endMoney=$("#endMoney").val();
			var rbState = document.getElementById("rbState");
			rbState=rbState.options[rbState.selectedIndex].value;
			var rbType = document.getElementById("rbType");
			rbType=rbType.options[rbType.selectedIndex].value;
			var beginTime="";
			var begin=document.getElementsByName("rbBeginTime");
			for(var i=0;i<begin.length;i++)
			{
				if(begin[i].value!="")
				{
					beginTime=begin[i].value;
				}
				
			}
			var endTime="";
			var end=document.getElementsByName("rbEndTime");
			for(var i=0;i<end.length;i++)
			{
				if(end[i].value!="")
				{
					endTime=end[i].value;
				}
				
			}
			var url='<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/jspGetReimbursementByIBA.jsp';
			  $('#rbTable').datagrid({   
			      url:url,
			      queryParams:{rbNumber:rbNumber,beginMoney:beginMoney,endMoney:endMoney,rbState:rbState,rbType:rbType,beginTime:beginTime,endTime:endTime},
			      nowrap:false,
			      loadMsg:'正在加载数据，请稍等。。。',
				  fitColumns: true,
			      columns:[[   
					  {field:'id',title:'id',width:100,checkbox:true},  
					  {field:'name',title:'单据号',width:60,
						  //添加超级链 
		                     formatter:function(value,rowData,rowIndex){
		                    		 return "<a href='javaScript:void(0)' onclick=\"javaScript:showReimbursement('"+rowData.id+"')\">"+rowData.name+"</a>";  
				          }
						  }, 
			          {field:'ProjectNo',title:'项目编号',width:40}, 
			          {field:'ProjectName',title:'项目名称',width:60},
			          {field:'state',title:'单据状态',width:40},
			          {field:'Sum',title:'报销金额',width:40},
			          {field:'PayMethod',title:'付款方式',width:40},
			          {field:'RefeBursementType',title:'单据类型',width:40},
			          {field:'Time',title:'报销日期',width:60}
			      ]] 
			    }); 
		}


		function showReimbursement(oid)
		{
			var rows = $('#rbTable').datagrid('getSelections');
			var url="";
			if(rows[0].RefeBursementType=="项目报销")
			{
			 url="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/browseShowReimbursement.jsp?oid="+oid;
			}else
			{
			url="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/browseShowCommonReimbursement.jsp?oid="+oid;
			}
			window.open(url);
		}

		

		function editReimbursement()
		{
			var rows = $('#rbTable').datagrid('getSelections');
			var danjuhao="";
			for(var i=0;i<rows.length;i++)
			{
				danjuhao+="、"+rows[i].name;
			}
			
			if(rows.length>1)
			{
				$.messager.alert('提示',"一次只能修改一个报销单哦!您已选择"+danjuhao);
				
				return;
			}else
			{
				if(rows[0].state!="编制中")
				{
					$.messager.alert('提示',"报销单"+rows[0].name+"已在审核，不可编辑");
					return;
				}
			}
			var url="";
			if(rows[0].RefeBursementType=="项目报销")
			{
				url="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/browseUpdateReimbursement.jsp?oid="+rows[0].id;
			}else
			{
				url="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/browseUpdateCommonReimbursement.jsp?oid="+rows[0].id;
			}
			
			window.open(url);
		}

		function addReimbursementTab(tabObj,tabId,url,title)
		{
			var defaultTabId = "cmTabs";
			if(tabId){
				defaultTabId = tabId;
			}
			var tabDefault = {
				cache:false,
				href:url,
				title:title,
				selected: true,
				closable:true
			};

			
			var options ;
			if(tabObj){
			    var empty = {};
				options = $.extend(empty,tabDefault,tabObj);
			}else{
				options = tabDefault;
			}
			if($('#'+defaultTabId).tabs("exists",options.title)){
				$('#'+defaultTabId).tabs('select',options.title);
				var tab = $('#'+defaultTabId).tabs('getSelected');       
				$('#'+defaultTabId).tabs('update',{  
					        tab:tab,  
					        options:{  
					           title:options.title, 
					           href:url,
					           closable:true,  
					           fit:true,  
					           selected:true  
					        }}  );
			}else{
			    $('#'+defaultTabId).tabs('add',options);
			}
		}
		 var cmBaseUrl = '<%=baseUrl%>';

	function browseCreateProjectReimbursement()
	{
		var url="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/browseCreateReimbursement.jsp";
		window.open(url);
		}
	function browseCreateCommonReimbursement()
	{
		var url="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/browseCreateCommonReimbursement.jsp";
		window.open(url);
	}
		 
	</script>
</body>
</html>